import { COLUMN_WIDTH } from '@/utils/service.js'
import { dateFormat } from '@/utils/date'

export const createColumns = (vm) => [
  {
    title: '',
    width: 34,
    align: 'center',
    type: 'selection',
  },
  {
    title: '序号',
    key: 'id',
    align: 'center',
    width: 80,
    render(h, params) {
      return <div>{(vm.formData.pageNo - 1) * vm.formData.pageSize + params.index + 1}</div>
    },
  },
  {
    title: '稿件标题',
    align: 'center',
    width: COLUMN_WIDTH + 340,
    render(h, params) {
      return <article-title info={params.row}></article-title>
    },
  },
  { title: '稿件来源', key: 'source', align: 'center' },
  {
    title: '上传时间',
    align: 'center',
    width: COLUMN_WIDTH + 50,
    render(h, params) {
      return <div>{dateFormat(params.row.createTime || '', 'YYYY.MM.DD HH:mm:ss')}</div>
    },
  },
  {
    title: '池内采用量',
    align: 'center',
    key: 'adoptCount',
    sortable: 'custom',
    render(h, params) {
      return (
        <a class="a-normalize" onClick={() => vm.viewAdoptList(params.row)}>
          {params.row.adoptCount || 0}
        </a>
      )
    },
  },
  { title: '全平台采用量', key: 'adoptAllCount', align: 'center', sortable: 'custom' },
  { title: '点击总量', key: 'clickAllCount', align: 'center', sortable: 'custom' },
  {
    title: '操作',
    align: 'center',
    width: 100,
    render(h, params) {
      let button_assess = ''
      let button_issue = ''

      if (vm.hasPermission('article/spread/detail')) {
        button_assess = (
          <icon-button
            icon="assess_active"
            title="效果评估"
            activated={false}
            nativeOnClick={() => {
              vm.handleEffectAssess(params.row)
            }}
          ></icon-button>
        )
      }
      if (vm.hasPermission('article/spread/instruct')) {
        button_issue = (
          <icon-button
            icon="issueDirective_active"
            title="下发指令"
            class={button_assess && 'ml14'}
            activated={false}
            nativeOnClick={() => {
              vm.handleIssueDirective(params.row)
            }}
          ></icon-button>
        )
      }

      if (!button_assess && !button_issue) return h('span', vm.noBtnText)
      return (
        <div>
          {button_assess}
          {button_issue}
        </div>
      )
    },
  },
]
